package com.yunti.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.yunti.business.domain.BaseSchool;
import com.yunti.business.domain.BaseSubject;
import com.yunti.business.service.IOchestrateService;
import com.yunti.business.vo.req.OrchestrateReq;
import com.yunti.business.vo.res.OrchestrateRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/business/orchestrate")
public class OrchestrateController extends BaseController {

    @Autowired
    private IOchestrateService orchestrateService;

    @GetMapping("/list")
    public TableDataInfo list(OrchestrateReq orchestrateReq)
    {
//        startPage();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        return orchestrateService.list(orchestrateReq,pageNum,pageSize);
    }

    @PostMapping("/update")
    public AjaxResult update(OrchestrateRes orchestrate)
    {
//        startPage();
        return orchestrateService.update(orchestrate);
    }

    @PostMapping("/lottery")
    public AjaxResult lottery(OrchestrateRes orchestrate)
    {
//        startPage();
        return orchestrateService.lottery(orchestrate);
    }


    /**
     * 导出学校列表
     */
    @Log(title = "学校", businessType = BusinessType.EXPORT)
    @PostMapping("/outputExcel")
    public void outputExcel(HttpServletResponse response)
    {
        try {
            orchestrateService.outputExcel(response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 导出学校列表
     */
    @Log(title = "学校", businessType = BusinessType.EXPORT)
    @PostMapping("/outputJianlu")
    public void outputJianlu(HttpServletResponse response, @RequestParam("subId") Long subId)
    {
        try {
            orchestrateService.outputJianlu(response,subId);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 导出学校列表
     */
    @Log(title = "学校", businessType = BusinessType.EXPORT)
    @PostMapping("/outputLotteryWord")
    public void outputLotteryWord(HttpServletResponse response, @RequestParam("subId") Long subId)
    {
        try {
            orchestrateService.outputLotteryWord(response,subId);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }



}
